Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

google-protobuf

Package Overview
Dependencies
Maintainers
6
Versions
91
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

google-protobuf

Protocol Buffers for JavaScript

  • 3.21.4
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
2.1M
decreased by-1.32%
Maintainers
6
Weekly downloads
 
Created

What is google-protobuf?

The google-protobuf npm package provides a library for serializing structured data. It is used to compile .proto files to construct and parse protocol buffers in JavaScript. Protocol buffers are Google's language-neutral, platform-neutral, extensible mechanism for serializing structured data.

What are google-protobuf's main functionalities?

Serialization and Deserialization

This feature allows you to serialize your structured data to a binary format and then deserialize it back to a JavaScript object. The code sample shows how to serialize and deserialize a message using the google-protobuf package.

const messages = require('./example_pb');

// Serialization
const message = new messages.ExampleMessage();
message.setSomeField('Hello, Protocol Buffers!');
const bytes = message.serializeBinary();

// Deserialization
const receivedMessage = messages.ExampleMessage.deserializeBinary(bytes);
console.log(receivedMessage.getSomeField());

Defining Message Structure

Before you can serialize and deserialize data, you need to define the structure of your messages using the Protocol Buffers language. This code sample is a .proto file that defines a simple message with one field.

// example.proto
syntax = 'proto3';

package example;

message ExampleMessage {
  string some_field = 1;
}

Working with Enums

Protocol Buffers allow you to define enums within your .proto files. This code sample shows how to define an enum and use it within a message.

// example.proto
syntax = 'proto3';

package example;

enum ExampleEnum {
  UNKNOWN = 0;
  STARTED = 1;
  COMPLETED = 2;
}

message ExampleMessage {
  ExampleEnum status = 1;
}

Other packages similar to google-protobuf

FAQs

Package last updated on 15 Jul 2024

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc